#ifndef _FILTER_H
#define _FILTER_H

#ifdef __cplusplus
extern "C" {
#endif

// given an array of filter coefficients in SOS form,
// evaluates to the number of sections in the filter (L)
#define IIR_SOS_L(x) (sizeof(x)/sizeof(*(x))/6)

typedef struct {
	const double *sos;	// array of filter coefficients
	const double *g;	// array of gain factors
	double *w;			// internal state
	size_t L;			// the number of sections in the filter
} iir_sos;

// Initialize a new filter object from its coefficients
// sos is the coefficients in SOS (secord order section) form
// that is, it is a 6*L array of values
// L is the number of 2nd order sections in the filter
// w should be a contiguous block of memory that the filter can use to store
// its data. It should be length 2*L
void iir_sos_init(iir_sos *f, const double *sos, const double *g, size_t L);

// Release all resources associated with the filter
void iir_sos_free(iir_sos *f);

// Compute output y for input x using Cascade Direct Form-II Transpose implementation
double iir_sos_filter(iir_sos *f, double x);

// Reset the state of the filter
void iir_sos_reset(iir_sos *f);

/****************************************************************************
							DC Blocking Filter
****************************************************************************/

typedef struct {
	double prev_e;
	double prev_x;
	double prev_y;
} dc_block;

void dc_block_init(dc_block *d);

void dc_block_free(dc_block *d);

double dc_block_filter(dc_block *t, double x);


#ifdef __cplusplus
}	// extern C
#endif

#endif // _FILTER_H
